<?php

/**
 * This is the model class for table "cs_proportion".
 *
 * The followings are the available columns in table 'cs_proportion':
 * @property integer $id
 * @property integer $company
 * @property integer $proportion
 * @property string $insure_number
 * @property integer $diff_number
 * @property integer $fail_number
 * @property integer $fail_time
 * @property integer $fail_limit
 * @property integer $total_number
 * @property integer $return_number
 * @property integer $roll_number
 */
class Proportion extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'cs_proportion';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('company, proportion, insure_number, fail_number, fail_time, fail_limit', 'required'),
			array('company, proportion, diff_number, fail_number, fail_time, fail_limit, total_number, return_number, roll_number', 'numerical', 'integerOnly'=>true),
			array('insure_number', 'length', 'max'=>11),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, company, proportion, insure_number, diff_number, fail_number, fail_time, fail_limit, total_number, return_number, roll_number', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'company' => 'Company',
			'proportion' => 'Proportion',
			'insure_number' => 'Insure Number',
			'diff_number' => 'Diff Number',
			'fail_number' => 'Fail Number',
			'fail_time' => 'Fail Time',
			'fail_limit' => 'Fail Limit',
			'total_number' => 'Total Number',
			'return_number' => 'Return Number',
			'roll_number' => 'Roll Number',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('company',$this->company);
		$criteria->compare('proportion',$this->proportion);
		$criteria->compare('insure_number',$this->insure_number,true);
		$criteria->compare('diff_number',$this->diff_number);
		$criteria->compare('fail_number',$this->fail_number);
		$criteria->compare('fail_time',$this->fail_time);
		$criteria->compare('fail_limit',$this->fail_limit);
		$criteria->compare('total_number',$this->total_number);
		$criteria->compare('return_number',$this->return_number);
		$criteria->compare('roll_number',$this->roll_number);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Proportion the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
